<?php
	require_once('../includes/config.php');
	$action = $_REQUEST['act'];
	$catid = $_POST['id'];
	$name = $_POST['name'];
	$des = $_POST['des'];	

	if($action == "add")
	{

		$sql_insert = "INSERT INTO tbl_category (name, description) VALUES ('$name', '$des')";
		mysql_query($sql_insert) or die("can not insert into database");
		echo 1;
		exit;
	}
	elseif($action == "edit")
	{
		mysql_query("UPDATE tbl_category SET name = '$name', description = '$des' WHERE id = '$catid'") or die("can not update");
		echo 1;
		exit;
	}
	elseif($_GET['act'] == "del")
	{
		$id = $_REQUEST['id'];
		//delete category
		mysql_query("DELETE FROM tbl_category WHERE id = '$id'");
		//delete all product of this category
		mysql_query("DELETE FROM tbl_product WHERE pro_cat = '$id'");
		echo 1;
		exit;
	}


?>